package com.ham.mud.commands.spells.heal;

import com.ham.mud.ServerConnection;
import com.ham.mud.TargetableService;
import com.ham.mud.characters.player.Player;
import com.ham.mud.commands.spells.Spell;
import com.ham.mud.rooms.Room;
import com.ham.mud.rooms.RoomService;

/**
 * Created by hlucas on Jul 6, 2011 at 10:51:39 AM
 */
public abstract class HealingSpell extends Spell {
    @Override
    public void castSpell(ServerConnection connection, String target) {
        Player player = connection.getPlayer();
        int mana = player.getVitals().getMana();
        int manaCost = getManaCost();
        int healAmount = (int) (getHealAmount()*player.getIntelligenceModifier());
        if(mana < manaCost) {
            connection.printSolo("You do not have enough mana to cast that spell.");
            return;
        }

        Room room = RoomService.getRoom(player.getZone(), player.getAtX(), player.getAtY());
        if(target == null || target.equals("")) {
            player.getVitals().decrementMana(manaCost);
            player.getVitals().incrementHealth(healAmount);
            connection.printSolo("You pray to the gods and you feel better.");
        } else {
            Player targetPlayer = (Player) TargetableService.findTarget(target, room.getOtherPlayers(connection));
            if(targetPlayer == null) {
                connection.printSolo("You do not see that person here.");
                return;
            }
            player.getVitals().decrementMana(manaCost);
            targetPlayer.getVitals().incrementHealth(healAmount);
            connection.printSolo("You deliver a prayer to the gods and the gods deliver health to " + targetPlayer.getName() + ".");
            room.printToOthers(player.getName() + " says a few prayers.", connection);
        }
    }

    protected abstract double getHealAmount();
    public abstract int getManaCost();
}
